<template>
	<view>
		<view class="selfcheck">
			<u-navbar title="自助验券" :title-size="35" :title-bold="true" :immersive="true" :background="background"
				:border-bottom="false"></u-navbar>
			<!-- 抖音 -->
			<view v-if="typeApp==1">
				<view class="toptab">
					<view class="tiktok" @click="changetype(1)">
						<image src="https://gongxiangtaiqiu.axa2.com/taiqiu/tiktok.png" style="width: 100%; height: 100%;">
						</image>
					</view>
					<view class="Meituan" @click="changetype(2)">
						<image src="https://gongxiangtaiqiu.axa2.com/taiqiu/meituan_grey.png"
							style="width: 100%; height: 100%;"></image>
					</view>
				</view>
				<view class="box">
					<view class="title">
						<image src="https://gongxiangtaiqiu.axa2.com/taiqiu/yanjuan.png"
							style="width: 52rpx; height: 50rpx;margin-right: 10rpx;"></image>抖音自助验劵
					</view>
					<view class="content">
						<view class="con-lf">
							<input placeholder="点击输入卡券兑换码" v-model="douyin_msg" />
						</view>
						<view class="con-rg" @click="douyin_scan">
							<image src="https://gongxiangtaiqiu.axa2.com/taiqiu/qrr.png"
								style="width: 52rpx; height: 52rpx;">
							</image>
						</view>
					</view>
					<view class="btn" @click="submit(typeApp)" v-if="isloding==false">
						<view class="btn-p">
							确认兑换核销
						</view>
					</view>
					<view class="btn" v-if="isloding==true">
						<view class="btn-p">
							确认兑换核销
						</view>
					</view>
					<!-- <view class="btn">
						<view class="btn-p">
							确认兑换核销
						</view>
					</view> -->
				</view>
			</view>
			<!-- 美团 -->
			<view v-if="typeApp==2">
				<view class="toptab">
					<view class="tiktok" @click="changetype(1)">
						<image src="https://gongxiangtaiqiu.axa2.com/taiqiu/tiktok_grey.png"
							style="width: 100%; height: 100%;"></image>
					</view>
					<view class="Meituan" @click="changetype(2)">
						<image src="https://gongxiangtaiqiu.axa2.com/taiqiu/meituan_quan.png"
							style="width: 100%; height: 100%;"></image>
					</view>
				</view>
				<view class="box">
					<view class="title">
						<image src="https://gongxiangtaiqiu.axa2.com/taiqiu/Meituan.png"
							style="width: 52rpx; height: 50rpx;margin-right: 10rpx;"></image>美团自助验劵
					</view>
					<view class="content">
						<view class="con-lf">
							<input placeholder="点击输入卡券兑换码" v-model="meituan_msg" />
						</view>
						<view class="con-rg" @click="meituan_scan">
							<image src="https://gongxiangtaiqiu.axa2.com/taiqiu/qrr.png"
								style="width: 52rpx; height: 52rpx;">
							</image>
						</view>
					</view>
					<view class="btn" @click="submit(typeApp)" v-if="isloding==false">
						<view class="btn-p" style="color: #ffc829;">
							确认兑换核销
						</view>
					</view>
					<view class="btn" v-if="isloding==true">
						<view class="btn-p" style="color: #ffc829;">
							确认兑换核销
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import getEqInfoForCode from '../../api/api.js'
	export default {
		data() {
			return {
				typeApp: 1,
				douyin_msg: '',
				meituan_msg: '',
				shopId: '',
				eqId: '',
				eqNo: '',
				isloding: false,
			};
		},
		onLoad(options) {
			console.log(options, 'options')
			this.shopId = options.shop_id
			this.eqId = options.eqId
			this.eqNo = options.eqNo
			this.typeApp = options.typeApp
			console.log(this.typeApp, 'onload  typeApp的值')
		},

		methods: {
			//美团扫码
			meituan_scan() {
				uni.scanCode({
					success: (res) => {
						console.log(res);
						this.meituan_msg = res.result
					}
				})
			},
			//抖音扫码
			douyin_scan() {
				uni.scanCode({
					success: (res) => {
						console.log(res,'抖音');
						this.douyin_msg = res.result
					}
				})
			},
			//确认核销
			submit(typeApp) {
				this.isloding = true
				console.log(typeApp, 'ehsgduyewgdeshg')
				if (typeApp == 2) {
					this.$Api.createMtOrder({
						code: this.meituan_msg,
						shopId: this.shopId,
						isCheck: 2,
						userId: uni.getStorageSync('userid'),
						eqId: this.eqId,
						eqNo: this.eqNo,
					}).then(res => {
						if (res.data.code == 0) {
							uni.showToast({
								icon: 'none',
								title: '核销成功'
							})	
						} else if (res.data.code == 1) {
							uni.showToast({
								icon: 'none',
								title: res.data.data
							})
							this.isloding = false
							console.log(res)
						}
					})
				}else if (typeApp == 1){
					this.$Api.createDyOrder({
						code: this.douyin_msg,
						shopId: this.shopId,
						isCheck: 2,
						userId: uni.getStorageSync('userid'),
						eqId: this.eqId,
						eqNo: this.eqNo,
					}).then(res => {
						if (res.data.code == 0) {
							uni.showToast({
								icon: 'none',
								title: '核销成功'
							})	
						} else if (res.data.code == 1) {
							uni.showToast({
								icon: 'none',
								title: res.data.data
							})
							this.isloding = false
							console.log(res)
						}
					})
					
				}
			},
			changetype(e) {
				this.typeApp = e
				console.log('e：', e, this.typeApp, '当前typeApp的值')
			}

		},
		mounted() {

		}
	}
</script>


<style lang="scss">
	page {
		background-color: #ffffff;
	}

	.selfcheck {
		width: 100%;
		height: auto;
	}

	.toptab {
		width: 700rpx;
		height: 55rpx;
		margin: auto;
		margin-top: 100px;
		display: flex;
		justify-content: space-between;
		align-items: center;

		.tiktok {
			width: 350rpx;
			height: 55rpx;
		}

		.Meituan {
			width: 350rpx;
			height: 55rpx;
		}
	}

	.box {
		width: 690rpx;
		height: 505rpx;
		background: #F5F5F5;
		border-radius: 16rpx;
		margin: auto;
		margin-top: 50rpx;
		padding-top: 70rpx;

		.title {
			width: 300rpx;
			margin: auto;
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #222222;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.btn {
			width: 630rpx;
			height: 88rpx;
			background: #222222;
			border-radius: 44rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			margin: auto;
			margin-top: 70rpx;

			.btn-p {
				// width: 178rpx;
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #02FF83;
			}
		}

		.content {
			width: 630rpx;
			height: 108rpx;
			background: #FFFFFF;
			border-radius: 8rpx;
			margin: auto;
			margin-top: 50rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.con-lf {
				width: 380rpx;
				height: 100rpx;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.con-rg {
				width: 130rpx;
				height: 100rpx;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}
	}
</style>